|
STEP 12: The Eerie Halloween Form
|
So far we've shown several ways in which a form can be sonified using the Music.sonifyFormsWithHandlers method. In the step Using the sonifyFormsWithHandlers Method, we showed how this method could be used to sonify a form using Groovoids, to achieve the same effect as using the more convenient Music.sonifyFormsWithGroovoids method. And in the step Using sonifyFormsWithHandlers to Play Musical Notes, we showed how this method could be used to sonify a form using musical notes, achieving sound textures that cannot be achieved by using only the Groovoids.
Of course, it doesn't end there. Because the Music.sonifyFormsWithHandlers method lets you specify any JavaScript code you desire to sonify the events of form elements, this means you can really add some serious intelligence to your form sonification. Your forms can sound dynamic and alive.
Below is a treatment of the same form we have been using in all the previous steps of this tutorial. Try it out. You will notice that it has a distinctively eerie Halloween-like sonification theme...
Take a look at the source code listing below to see what has been added since the previous step. New code is highlighted in red.
<HTML><HEAD><TITLE>Sonified Forms Example</TITLE></HEAD> <BODY ONLOAD="sonifyForms ()"> <SCRIPT SRC="music-object.js"></SCRIPT> <SCRIPT SRC="music-object-x-dynamic.js"></SCRIPT> <SCRIPT SRC="music-object-x-wizards.js"></SCRIPT> <FORM NAME="productForm" METHOD=GET ACTION="thanks.html"> <CENTER> <TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=4> <TR> <TD ALIGN=CENTER BGCOLOR=003366> <FONT FACE="ARIAL,HELVETICA,VERDANA"> <FONT COLOR=00CCFF SIZE=6> Blue Bass & the Neurotic Fishes<BR> </FONT> <FONT COLOR=FFFFFF SIZE=5> -- Merchandise -- </FONT> </FONT> </TD> </TR> <TR> <TD BGCOLOR=666699> <FONT FACE="ARIAL,HELVETICA,VERDANA"> <CENTER><FONT SIZE=5>1. Select your poison...</FONT></CENTER> <P> <INPUT TYPE=checkbox NAME=tshirt> <B>T-shirt ($15.95)</B> <P> <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Color</TD> <TD> <SELECT NAME=tshirtColor> <OPTION>Oil Slick Black <OPTION>Spiritual White <OPTION SELECTED>Blood Clot Red <OPTION>Summer Sky Blue <OPTION>Underwater Aqua <OPTION>Radioactive Green <OPTION>Militia Khaki <OPTION>Neon Pink </SELECT> </TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Size</TD> <TD> <INPUT TYPE=radio NAME=tshirtSize>Small <INPUT TYPE=radio NAME=tshirtSize CHECKED>Medium <INPUT TYPE=radio NAME=tshirtSize>Large <INPUT TYPE=radio NAME=tshirtSize>X-Large <INPUT TYPE=radio NAME=tshirtSize>XX-Large </TD> </TR> </TABLE> <HR SIZE=1 NOSHADE> <INPUT TYPE=checkbox NAME=mug> <B>Commemorative Reunion Mug ($19.95)</B> - with printed mugshot of a band member of your choice <P> <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Band Member</TD> <TD> <SELECT NAME=mugPicture> <OPTION SELECTED>Blue Bass (lead vocals & bass guitar) <OPTION>Alec Littlefish (lead guitar & vocals) <OPTION>Joe "The Octopus" Malone (drums & percussion) <OPTION>Humphrey Proudfin (keyboards & vocals) <OPTION>Gill Stronglung (harmony vocals) <OPTION>Neville "The Blowfish" Ohrensborg (sax & horns) </SELECT> </TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Mug Size</TD> <TD> <SELECT NAME=mugSize> <OPTION>Diet Size (9 Fl.Oz.) <OPTION SELECTED>Average Stomach (12 Fl.Oz) <OPTION>Big Mama (20 Fl.Oz) </SELECT> </TD> </TR> </TABLE> <HR SIZE=1 NOSHADE> <B>Albums ($15.95 each)</B> <P> <INPUT TYPE=checkbox NAME=album1989> Underwater Blues (released 1989)<BR> <INPUT TYPE=checkbox NAME=album1991> The Suffocating Sky (released 1991)<BR> <INPUT TYPE=checkbox NAME=album1992> Suckerfish Rising (released 1992)<BR> <INPUT TYPE=checkbox NAME=album1994> Psychedelic Abyss (released 1994)<BR> <INPUT TYPE=checkbox NAME=album1997> The Little Fish That Could (released 1997)<BR> <INPUT TYPE=checkbox NAME=album1998> Have You Eaten Fish Today (new release)<BR> <HR SIZE=1 NOSHADE> </FONT> </TD> </TR> <TR> <TD BGCOLOR=9999CC> <FONT FACE="ARIAL,HELVETICA,VERDANA"> <CENTER><FONT SIZE=5>2. Pay for the poison...</FONT></CENTER> <P> <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Type of Credit Card</TD> <TD> <INPUT TYPE=radio NAME=creditCardType>American Express <INPUT TYPE=radio NAME=creditCardType CHECKED>VISA <INPUT TYPE=radio NAME=creditCardType>Mastercard </TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*Name on Credit Card</B></TD> <TD><INPUT TYPE=text SIZE=30 NAME=creditCardName></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*Credit Card Number</B></TD> <TD><INPUT TYPE=text SIZE=30 NAME=creditCardNumber></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Expiration Date</TD> <TD> <SELECT NAME=creditCardExpirationYear> <OPTION SELECTED>1998 <OPTION>1999 <OPTION>2000 <OPTION>2001 <OPTION>2002 <OPTION>2003 <OPTION>2004 </SELECT> <SELECT NAME=creditCardExpirationMonth> <OPTION SELECTED>01 Jan <OPTION>02 Feb <OPTION>03 Mar <OPTION>04 Apr <OPTION>05 May <OPTION>06 Jun <OPTION>07 Jul <OPTION>08 Aug <OPTION>09 Sep <OPTION>10 Oct <OPTION>11 Nov <OPTION>12 Dec </SELECT> </TD> </TR> </TABLE> <HR SIZE=1 NOSHADE> </FONT> </TD> </TR> <TR> <TD BGCOLOR=CCCCFF> <FONT FACE="ARIAL,HELVETICA,VERDANA"> <CENTER><FONT SIZE=5>3. Deliver the poison...</FONT></CENTER> <P> <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Shipping & Handling Option</TD> <TD> <SELECT NAME=shippingOption> <OPTION>US Mail (7 day delivery) <OPTION SELECTED>UPS (2 day delivery) <OPTION>Fedex (overnight delivery) </SELECT> </TD> </TR> <TR> <TD COLSPAN=2 ALIGN=CENTER> </TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*Name</B></TD> <TD><INPUT TYPE=TEXT NAME=shippingAddressName SIZE=40></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*Address Line 1</B></TD> <TD><INPUT TYPE=TEXT NAME=shippingAddressLine1 SIZE=40></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT>Address Line 2</TD> <TD><INPUT TYPE=TEXT NAME=shippingAddressLine2 SIZE=40></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*City</B></TD> <TD><INPUT TYPE=TEXT NAME=shippingAddressCity SIZE=40></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*State</B> (or Province, or Region)</TD> <TD><INPUT TYPE=TEXT NAME=shippingAddressState SIZE=40></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*Zip Code</B> (or Postal Code)</FONT></TD> <TD><INPUT TYPE=TEXT NAME=shippingAddressZip SIZE=40></TD> </TR> <TR VALIGN=TOP> <TD ALIGN=RIGHT><B>*Country</B></TD> <TD><INPUT TYPE=TEXT NAME=shippingAddressCountry SIZE=40 VALUE="USA"></TD> </TR> </TABLE> <HR SIZE=1 NOSHADE> </FONT> </TD> </TR> <TR> <TD BGCOLOR=000000> <TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0> <TR> <TD ALIGN=LEFT> <INPUT TYPE=reset VALUE="Reset and start over"> </TD> <TD ALIGN=RIGHT> <INPUT TYPE=submit NAME=submitButton VALUE="BUY the poison NOW!!!"> </TD> </TR> </TABLE> </TD> </TR> </TABLE> <P> </CENTER> </FORM> <SCRIPT LANGUAGE=JavaScript><!-- // notePlayer = new Music (); groovoidPlayer = new Music (); function checkboxCheckSound () { notePlayer.playRandomNote (1,1,82,84,105,30,20,1000,1000,100,100,0,127); notePlayer.playRandomNote (2,1,79,84,105,30,20,1000,1000,100,100,0,127); notePlayer.playRandomNote (3,0,128+71,85,102,40,40,200,200,100,100,0,127); } function checkboxUncheckSound () { notePlayer.playRandomNote (1,1,128+82,67,97,30,20,100,100,100,100,0,127); notePlayer.playRandomNote (2,1,128+82,67,97,30,20,100,100,100,100,0,127); notePlayer.playRandomNote (3,1,38,26,43,50,50,500,500,100,100,0,127); } function radioButtonSound () { notePlayer.playRandomNote (1,0,128+56,84,84,50,30,3000,3000,100,100,0,127); notePlayer.playRandomNote (2,1,119,25,50,100,100,3000,3000,100,100,0,127); notePlayer.playRandomNote (3,1,93,50,76,50,50,300,300,100,100,0,127); } function listFocusSound () { notePlayer.playRandomNote (1,1,5,25,50,100,100,5000,5000,100,100,0,127); } function listChooseSound () { notePlayer.playRandomNote (1,0,128+56,2,20,50,30,3000,3000,100,100,0,127); notePlayer.playRandomNote (2,0,128+56,2,20,50,30,3000,3000,100,100,0,127); notePlayer.playRandomNote (3,0,128+56,2,20,50,30,3000,3000,100,100,0,127); } function multilistChooseSound () { notePlayer.playRandomNote (1,1,11,50,76,40,80,3000,3000,100,100,0,127); } function startTypingSound () { notePlayer.playRandomNote (1,1,127,25,50,50,50,5000,5000,100,100,0,127); notePlayer.playRandomNote (2,1,33,36,50,100,100,3000,3000,100,100,0,127); groovoidPlayer.play ("Background-Beeps"); } function stopTypingSound () { notePlayer.playRandomNote (1,0,128+56,2,20,50,30,3000,3000,100,100,0,127); notePlayer.playRandomNote (2,0,128+56,2,20,50,30,3000,3000,100,100,0,127); notePlayer.playRandomNote (3,0,128+56,2,20,50,30,3000,3000,100,100,0,127); groovoidPlayer.stop (1000); } function formResetSound () { notePlayer.playRandomNote (1,1,33,41,54,100,100,2000,2000,100,100,64,64); notePlayer.playRandomNote (2,1,33,81,102,10,10,4000,4000,100,100,0,127); notePlayer.playRandomNote (3,1,33,81,102,10,10,4000,4000,100,100,0,127); notePlayer.playRandomNote (4,1,33,81,102,10,10,4000,4000,100,100,0,127); notePlayer.playRandomNote (5,1,33,81,102,10,10,4000,4000,100,100,0,127); } function formSubmitSound () { notePlayer.playRandomNote (1,1,50,54,80,100,100,500,500,60,60,64,64); notePlayer.playRandomNote (2,1,50,54,80,100,100,500,500,60,60,64,64); notePlayer.playRandomNote (3,1,50,54,80,100,100,500,500,60,60,64,64); notePlayer.playRandomNote (4,1,50,54,80,100,100,500,500,60,60,64,64); } function sonifyForms () { Music.noManualHandlers = true; document.productForm.submitButton.onclick = new Function ('return false'); Music.sonifyFormsWithHandlers ( 'checkboxCheckSound ()', 'checkboxUncheckSound ()', 'radioButtonSound ()', 'listFocusSound ()', 'listChooseSound ()', '', '', 'multilistChooseSound ()', '', 'startTypingSound ()', 'stopTypingSound ()', '', 'formResetSound ()', 'formSubmitSound ()' ); } notePlayer.stubEmbed ('stub.rmf'); groovoidPlayer.stubEmbed ('stub.rmf'); // --></SCRIPT> </BODY></HTML> |
In the source code listing above, all the code needed for sonification of the form is highlighted in red. Towards the bottom of the source code listing you will see the block of code (highlighted in red) that is responsible for actually sonifying the form.
In contrast to the earlier steps in this tutorial using the Music.sonifyFormsWithHandlers method, instead of specifying the full implementation of the sonification behaviors for the various form element events in the call to the Music.sonifyFormsWithHandlers method, we are now just specifying calls to custom functions which contain the implementations for the sonification behaviors. This is primarily because the sonification behaviors are more complex in this example and, therefore, require more code. Specifying the full implementations in the call to the Music.sonifyFormsWithHandlers method would create code that is unwieldly and hard to read - not to mention hard to edit and update. You can see the definitions of all these functions in the source listing, right above the definition of the sonifyForms function.
You should notice some other key differences between this step and earlier steps...